# coding: utf-8
'''
题目四：新建“test4”Python文件：读取素材中的“test.txt”文件，使用jieba库进行分词，并将出现次数前5的词汇和出现次数信息写入到“output.txt”文件中。（40分）
'''
import jieba
import jieba.analyse
fp=open('test.txt','r',encoding='utf-8')
out=open('output.txt','w',encoding='utf-8')
text=fp.read()
# print(text)



key_words=jieba.analyse.textrank(text,topK=5,withWeight=True,\
allowPOS=('ns','n','nr'),withFlag=False)
key_words
for i in key_words:
    out.write(str(i))
    out.write('\n')
    print(i)